package com.test33_反射;

import org.junit.Test;

/**
 * 反射获取类结构信息
 */
public class Demo05_ClassStruct {

    @Test
    public void test1() throws Exception {
        Class<?> clazz = Class.forName("com.test33_反射.Book5");
        System.out.println(clazz.getPackage());     // 获取包名称
    }

    @Test
    public void test2() throws Exception {
        Class<?> clazz = Class.forName("com.test33_反射.Book5");
        // 获取父类
        Class<?> superClazz = clazz.getSuperclass();
        while (superClazz != null) {
            System.out.println("【继承父类】" + superClazz.getName());
            superClazz = superClazz.getSuperclass();
        }
        // 获取实现的接口
        Class<?>[] inters = clazz.getInterfaces();
        for (Class<?> temp : inters) {
            System.out.println("【实现接口】" + temp.getName());
        }
    }
}

interface IBook5 {
}

interface ISpec5 {
}

abstract class AbstractPrint5 {
}

class Book5 extends AbstractPrint5 implements IBook5, ISpec5 {
}
